home *** CD-ROM | disk | FTP | other *** search
/ PC Media 2 / PC MEDIA CD02.iso / share / prog / realasm1 / st2ft.asm < prev    next >
Encoding:
Assembly Source File  |  1993-07-18  |  3.6 KB  |  92 lines

  1. .286
  2. ;================================================
  3. ; invoke st2ft, real, string
  4. ;
  5. ; Convert an ascii string to a REAL10
  6. ; where string is '+(or -)integers[.decimals]',0
  7. ;------------------------------------------------
  8. cseg          segment word public 'code'
  9.               assume  cs:cseg,ss:cseg
  10.               assume  ds:cseg,es:cseg
  11.  
  12.               include math.inc
  13.  
  14. st2ft         proc    near  real:NPR10, string:NPB
  15.               local   exp:SWORD, t:REAL10, r:REAL10
  16.  
  17.               pusha                             ;
  18.               mov     si, string                ;
  19.               mov     di, real                  ;
  20.               cld                               ;
  21.  
  22.               invoke  load1, di                 ; real = 1.0
  23.  
  24.               .WHILE (1)                        ; skip whitespace
  25.                  lodsb                          ;
  26.                  .BREAK .IF (al != ' ')         ;
  27.               .ENDW                             ;
  28.  
  29.               .IF (al == '-')                   ; if negative
  30.                  or      word ptr [di]+8, 8000h ;
  31.               .ELSEIF ((al != '+') && (al != '-'))
  32.                  dec     si                     ;
  33.               .ENDIF                            ;
  34. ;------------------------------------------------
  35. ; process integers
  36. ;------------------------------------------------
  37.               xor     dx, dx                    ; DX = 0
  38.  
  39.               .WHILE (1)                        ;
  40.                  lodsb                          ;
  41.                  .BREAK .IF ((al < '0') || (al > '9'))
  42.                  xor     ah, ah                 ;
  43.                  sub     al, '0'                ; make binary word
  44.                  invoke  itoft, addr t, ax      ; convert word to REAL10
  45.                  invoke  ftmuli, di, +10        ; real * 10
  46.                  invoke  ftadd, di, addr t      ; add digit
  47.  
  48.                  .IF (dx == 0)                  ;
  49.                     invoke  ftsubi, di, +10     ;
  50.                  .ENDIF                         ;
  51.                  or      dx, 1                  ; once only
  52.               .ENDW
  53. ;------------------------------------------------
  54. ; exit if no decimal point
  55. ;------------------------------------------------
  56.               .IF (al != '.')
  57.                  jmp     exit
  58.               .ENDIF
  59. ;------------------------------------------------
  60. ; process decimals
  61. ;------------------------------------------------
  62.               mov     exp, 0                    ; exp == 0
  63.               invoke  load1, addr r             ; r[] = 1.00
  64.  
  65.               .WHILE (1)                        ;
  66.                  lodsb                          ; load byte
  67.                  .BREAK .IF ((al < '0') || (al > '9'))
  68.                  xor     ah, ah                 ;
  69.                  sub     al, '0'                ; make binary word
  70.                  invoke  itoft, addr t, ax      ; convert word to REAL10
  71.                  inc     exp                    ; exp++
  72.                  mov     bx, exp                ; save exp
  73.  
  74.                  .WHILE (exp > 0)               ;
  75.                     dec     exp                 ;
  76.                     invoke  ftdivi, addr t, +10 ; t /= 10
  77.                  .ENDW                          ;
  78.                  mov     exp, bx                ; recover exp
  79.                  invoke  ftadd, addr r, addr t  ; r[] += t[]
  80.               .ENDW
  81.  
  82.               invoke  ftsubi, addr r, +1        ; r[] -= 1.00
  83.               invoke  ftadd, di, addr r         ; real += r[]
  84. exit:
  85.               popa
  86.  
  87.               ret
  88. st2ft         endp
  89.  
  90. cseg          ends
  91.               end
  92.